import java.util.ArrayList;

public class ShoppingCart {
    private ArrayList<Item> items=new ArrayList<>();
    public void add(Item item,int num){
        items.add(item);
        item.setNumber(num);
    }
    public void Delete(Item item){
        items.remove(item);
    }
    public void calculatePrice(){
        double price=0;
        for (Item item : items){
            price+=item.getPrice();
        }
        System.out.println("一共"+price+"元");
    }

    public ArrayList<Item> getItems() {
        return items;
    }

    @Override
    public String toString() {
        if(items.isEmpty()){
            return "购物车内没有物品。";
        }
        StringBuffer stringBuffer=new StringBuffer();
        int number=1;
        for (Item item:items){
            stringBuffer.append(number).append("：").append(item).append("\n");
            number++;
        }
        return stringBuffer.toString();
    }
}
